/*接口*/
import request from '../request'
import config from '../config'

function jsonToUrl (json){
	//var json = { sh: '上海' };
	var params = Object.keys(json).map(function (key) {
		return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
	}).join("&");
	return params;
}
	
/**
 * 拿货来源，固定
 */
export function siteFrom() {
	return [{ name: '公司直发' }, { name: '其他店面' }]
}

/**
 * 选择店面列表接口
 */
export function xdStoreList(data,success,fail) {
	return request({
		url: config.api + '/xdstore/storeBasics/wwd/list'+'?'+jsonToUrl(data),
		method: 'get',
		data,
		success,
		fail
	})
}

/**
 * 新增微网点
 */
export function addSite(data,success,fail) {
	return request({
		url: config.api + '/offline/site',
		method: 'post',
		data,
		success,
		fail
	})
}

/**
 * 发起审批
 */
export function siteSp(data,success,fail) {
	return request({
		url: config.api + '/offline/site/siteSp',
		method: 'post',
		data,
		success,
		fail
	})
}

/**
 * 扫描身份证信息
 */
export function getIdCardInfo(data,success,fail) {
	return request({
		url: config.api + '/offline/site/getIdCardInfo?imgUrl='+data.url,
		method: 'get',
		data,
		success,
		fail
	})
}

/**
 * 微网点列表
 */
export function list(data,success,fail) {
	return request({
		url: config.api + '/offline/site/list'+'?'+jsonToUrl(data),
		method: 'get',
		data,
		success,
		fail
	})
}

/**
 * 微网点详情
 */
export function getSite(data,success,fail) {
	return request({
		url: config.api + '/offline/site'+'/'+data.id,
		method: 'get',
		data,
		success,
		fail
	})
}

/**
 * 查询审批列表
 */
export function wxspList(data,success,fail) {
	return request({
		url: config.api + '/wxsp/offlinesite/list'+'?'+jsonToUrl(data),
		method: 'get',
		data,
		success,
		fail
	})
}

/**
 * 查询审批详情
 */
export function wxspDetail(data,success,fail) {
	return request({
		url: config.api + '/wxsp/offlinesite'+'/'+data.id,
		method: 'get',
		// data,
		success,
		fail
	})
}

/**
 * 查询审批节点
 */
export function wxSpGetSpNode(data,success,fail) {
	return request({
		url: config.serviceurl + '/WxService?method=wxSpGetSpNode',
		method: 'post',
		data,
		success,
		fail
	})
}

/**
 * 查一级销区
 */
export function getXQ1ByMemCode(data, success, fail) {
  return request({
    url: config.crmApiUrl + "getXQ1ByMemCode",
    method: "post",
    data,
    success,
    fail,
  });
}

/**
 * 查二级销区
 */
export function getXQ2ByMemCodeAndXQ1(data, success, fail) {
  return request({
    url: config.crmApiUrl + "getXQ2ByMemCodeAndXQ1",
    method: "post",
    data,
    success,
    fail,
  });
}

/**
 * 查品牌
 */
export function getBrandByMemCodeAndXQ2(data, success, fail) {
  return request({
    url: config.crmApiUrl + "getBrandByMemCodeAndXQ2",
    method: "post",
    data,
    success,
    fail,
  });
}


